import api, gui, tones, ui, wx
timer = None
watching = None
lastText = None
def init():
    # 初始化
    global timer
    timer = wx.Timer(gui.mainFrame)
    gui.mainFrame.Bind(wx.EVT_TIMER, onTimerEvent, timer)
def release ():
    global timer
    # 释放资源
    if not timer: return
    timer.Stop()
    lastText, timer, watching = None, None, None
def watchNavigatorObject ():
    global watching
    # 监视开关
    if not timer: return
    tones.beep(800, 50)
    if timer.IsRunning ():
        timer.Stop ()
        ui.message ('已关闭监视')
        return
    # 开始监视
    timer.Start (1000)
    watching = api.getNavigatorObject ()
    ui.message ('已开启监视%s' % watching.name)
def onTimerEvent(event):
    global lastText, watching
    if not watching: return
    # 监视处理
    try:
        text = watching.name
    except RuntimeError:
        timer.Stop ()
        return
    if not text:
        text = watching.description
        if not text:
            text = watching.displayText
    if lastText == text:return
    lastText = text
    ui.message(text)
